<?php
namespace app\admin\controller;
use think\Db;
use think\Request;
use think\Controller;
class Traindata extends ApiCommon
{   

    // 获取培训详情
    public function detail()
    {
      $model = model('Traindata');
      $id = $this->param['id'];
      $data = $model->detail($id);
      if ($data) {
        return resultArray(['data' => $data]);
      } else {
        return resultArray(['error' => $model->getError()]);
      }
    }
    
    //哪个学校
    public function TraindataSchool()
    {
        $newsModel=Model('Traindata');
        $param=$this->param;
        $data=$newsModel->SchoolTraindata($param);
        return resultArray(['data'=> $data]);
    }
    public function School()
    {
        $data=Db::table('oa_admin_school')
               ->field('sch_id,sch_code,sch_name')
               ->select();
        return resultArray(['data'=> $data]);
    }

    //培优信息录入
    public function TraindataInsert()
    {
        $newsModel = model('Traindata');
        $param=$this->param;
        $data=$newsModel->InsertTraindata($param);
        if(!$data)
        {
            return resultArray(['error'=>'培训信息已存在']);
        }
        return resultArray(['data'=>'添加成功']); 
            

    }
 
    //培优信息修改
    public function TraindataRevise()
    {
        $newsModel=model('Traindata');
        $param=$this->param;
        $data=$newsModel->ReviseTraindata($param);
        if(!$data)
        {
            return resultArray(['error'=>$newsModel->getError()]);
        }
        return resultArray(['data'=>'培训信息修改成功']);
    }

    //培优信息删除
    public function TraindataDelete()
    {
        $newsModel=model('Traindata');
        $param=$this->param;
        $data=$newsModel->DeleteTraindata($param);
        if(!$data){
          return resultArray(['error'=>$newsModel->getError()]);
        }
        return resultArray(['data'=>'培训信息删除成功']);
    }
   //辅导员申请培训
    public function TraindataApply()
    {
        $newsModel = model('Traindata');
        $param=$this->param;
        $data=$newsModel->ApplyTraindata($param);
        if(!$data)
        {
            return resultArray(['error'=>$newsModel->getError()]);
        }
        return resultArray(['data'=>'申请成功']);
    }

    //辅导员查看自己的培训信息
   public function TraindataListtrain()
    {
        $newsModel=model('Traindata');
        $param=$this->param;
        $data=$newsModel->ListtrainTraindata($param);
        return resultArray(['data'=> $data]);
    }
     //按日期排列的所有培训信息列表与搜索
       public function TraindataList()
    {
        $newsModel=model('Traindata');
        $param=$this->param;
        $data=$newsModel->ListTraindata($param);
        return resultArray(['data'=> $data]);
    }
    //教育厅审核培训信息
    public function TraindataCheckedu()
    {
        $newsModel=model('Traindata');
        $param=$this->param;
        $data=$newsModel->CheckeduTraindata($param);
        if(!$data){
            return resultArray(['error'=>'审核状态修改失败']);
        }
        return resultArray(['data'=>'审核状态修改成功']);
    }
    //教育厅结束培训  
    public function TraindataEduend()
    {
        $newsModel=model('Traindata');
        $param=$this->param;
        $data=$newsModel->EduendTraindata($param);
        if(!$data){
            return resultArray(['error'=>'结束培训失败']);
        }
        return resultArray(['data'=>'结束培训成功']);
    } 
} 